<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>系统常态化运行评分系统</title>
    <link rel="stylesheet" href="../component/pear/css/pear.css" />
    <style>
        .expand.pear-btn:hover {
            color: currentColor;
            background: none;
        }

        .expand.pear-btn {
            border: 1px solid rgba(255, 255, 255, 0)
        }
    </style>
</head>

<body class="pear-container">

    <!-- 上传文件模态框 -->
    <div id="upload-modal">
        <div class="layui-form">
            <div class="layui-upload">
                <button type="button" class="layui-btn pear-btn-primary layui-btn-sm" id="ID-upload-demo-files">
                    <i class="layui-icon layui-icon-upload"></i>
                    选择上传文件</button>
                <button type="button" class="layui-btn pear-btn-primary layui-btn-sm" id="ID-upload-demo-files-action">提交</button>
                <div id="divUploadResult" class="layui-upload-list">
                    
                </div>
            </div>
        </div>
    </div>

    <script src="../component/layui/layui.js"></script>
    <script src="../component/pear/pear.js"></script>
    <script src="../scripts/utils/request.js"></script>
    <script src="../scripts/utils/auth.js"></script>
    <script>

        var pfId=getUrlParams("pfId");
        var pfSystemId=getUrlParams("pfSystemId");
        var index = parent.layer.getFrameIndex(window.name); 

        var uploadFileUrl;
        var $, table, form, drawer, popup, notice, upload
        layui.use(['table', 'form', 'jquery', 'drawer', 'popup', 'notice', 'upload'], function () {
            table = layui.table;
            form = layui.form;
            $ = layui.jquery;
            drawer = layui.drawer;
            popup = layui.popup;
            notice = layui.notice;
            upload = layui.upload;
            initUpload()
            // 初始化上传组件
            function initUpload() {
                var uploadListIns = upload.render({
                    elem: '#ID-upload-demo-files',
                    url: baseURL + '/api/file/uploadMinePf?taskId=' + pfId, // 替换为你的上传接口
                    accept: 'file',
                    multiple: false,
                    field:"file",
                    dataType:'json',
                    unified:false,
                    headers:{token:localStorage.getItem("token")},
                    auto: true,
                    done: function (res, index, upload) { // 成功的回调
                        notice.success('上传文件成功！'+JSON.stringify(res.data));
                        $('#divUploadResult').html(res.data)
                        uploadFileUrl=res.data;
                    },
                    error: function (index, upload) { // 错误回调
                        var tr = $('#ID-upload-demo-files-list').find('tr#upload-'+ index)
                        var tds = tr.children();
                        // 显示重传
                        tds.eq(3).find('.demo-reload').removeClass('layui-hide');
                    },
                });
            }
            $('#ID-upload-demo-files-action').click(function () {
                if(uploadFileUrl==null||uploadFileUrl==''){
                    notice.error('请上传文件');
                    return;
                }
                const reqData = {
                    pfSystemId: pfSystemId,
                    zpRemark: uploadFileUrl?uploadFileUrl:'',
                };
                postAjax('/api/pf/commitPfSystem', reqData, function (response) {
                    parent.changeCheck();
                    parent.layer.close(index);
                }, null);
            });

        })
    </script>
</body>

</html>